<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // function arr(head, val) {
    //   if (head === null) {
    //     return head;
    //   }
    //   head.next = removeElements(head.next, val);
    //   return head.val === val ? head.next : head;
    // };



    var removeElements = function (head, val) {
      if (!head) return null;
      next = removeElements(head.next, val);

      if (head.val === val) {
        return next;
      } else {
        head.next = next;
        return head;
      }
    };
    console.log(removeElements([1, 2, 6, 3, 4, 5, 6], 6));
  </script>
</body>

</html>